<template>
  <div class="home-page">
    <div class="hero-section">
      <h1 class="hero-title">欢迎来到 AI Market</h1>
      <p class="hero-description">
        探索最新的AI应用，发现无限可能
      </p>
      <div class="hero-actions">
        <a-button type="primary" size="large" @click="exploreApps">
          探索应用
        </a-button>
        <a-button size="large" @click="createApp">
          创建应用
        </a-button>
        <a-button type="dashed" size="large" @click="testGetLoginUser" :loading="testLoading">
          测试获取用户信息
        </a-button>
      </div>
    </div>
    
    <div class="features-section">
      <h2 class="section-title">平台特色</h2>
      <a-row :gutter="[24, 24]">
        <a-col :xs="24" :sm="12" :md="8">
          <a-card class="feature-card">
            <template #cover>
              <div class="feature-icon">🚀</div>
            </template>
            <a-card-meta title="快速部署" description="一键部署AI应用，无需复杂配置" />
          </a-card>
        </a-col>
        <a-col :xs="24" :sm="12" :md="8">
          <a-card class="feature-card">
            <template #cover>
              <div class="feature-icon">🎯</div>
            </template>
            <a-card-meta title="精准匹配" description="智能推荐最适合的AI解决方案" />
          </a-card>
        </a-col>
        <a-col :xs="24" :sm="12" :md="8">
          <a-card class="feature-card">
            <template #cover>
              <div class="feature-icon">🔧</div>
            </template>
            <a-card-meta title="易于定制" description="灵活的配置选项，满足个性化需求" />
          </a-card>
        </a-col>
      </a-row>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { message } from 'ant-design-vue'
import { getUserInfo } from '@/api/auth'

const router = useRouter()
const testLoading = ref(false)

const exploreApps = () => {
  router.push('/apps')
}

const createApp = () => {
  router.push('/create')
}

const testGetLoginUser = async () => {
  try {
    testLoading.value = true
    console.log('开始测试获取用户信息...')
    
    // 检查是否有token
    const tokenName = localStorage.getItem('tokenName')
    const tokenValue = localStorage.getItem('tokenValue')
    
    if (!tokenName || !tokenValue) {
      message.warning('请先登录后再测试')
      return
    }
    
    console.log('当前token信息:', { tokenName, tokenValue })
    
    const response = await getUserInfo()
    console.log('getUserInfo 响应:', response)
    
    if (response.code === 0) {
      message.success('获取用户信息成功！')
      console.log('用户信息:', response.data)
      
      // 显示用户信息的详细内容
      const userInfo = response.data
      message.info(`用户ID: ${userInfo.id}, 账号: ${userInfo.userAccount}`)
    } else {
      message.error(`获取用户信息失败: ${response.message}`)
      console.error('获取用户信息失败:', response)
    }
  } catch (error) {
    console.error('测试获取用户信息时发生错误:', error)
    message.error('请求失败，请检查网络连接和后端服务')
  } finally {
    testLoading.value = false
  }
}
</script>

<style scoped>
.home-page {
  padding: 0;
}

.hero-section {
  text-align: center;
  padding: 80px 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  margin: -24px -24px 40px -24px;
}

.hero-title {
  font-size: 48px;
  font-weight: 700;
  margin-bottom: 16px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.hero-description {
  font-size: 20px;
  margin-bottom: 32px;
  opacity: 0.9;
}

.hero-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
}

.features-section {
  padding: 40px 0;
}

.section-title {
  text-align: center;
  font-size: 32px;
  font-weight: 600;
  margin-bottom: 40px;
  color: #333;
}

.feature-card {
  height: 100%;
  transition: transform 0.3s, box-shadow 0.3s;
  cursor: pointer;
}

.feature-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.feature-icon {
  font-size: 48px;
  text-align: center;
  padding: 24px;
  background: #f8f9fa;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .hero-title {
    font-size: 36px;
  }
  
  .hero-description {
    font-size: 18px;
  }
  
  .hero-section {
    padding: 60px 20px;
  }
  
  .section-title {
    font-size: 28px;
  }
}

@media (max-width: 480px) {
  .hero-title {
    font-size: 28px;
  }
  
  .hero-description {
    font-size: 16px;
  }
  
  .hero-section {
    padding: 40px 16px;
  }
  
  .hero-actions {
    flex-direction: column;
    align-items: center;
  }
  
  .hero-actions .ant-btn {
    width: 200px;
  }
}
</style>